home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / More Files / form-to-email_comppre.php < prev    next >
PHP Script  |  2013-07-17  |  2KB  |  87 lines

  1. <?php
  2.  
  3. if(!isset($_POST['submit']))
  4. {
  5.     //This page should not be accessed directly. Need to submit the form.
  6.     echo "error; you need to submit the form!";
  7. }
  8.  
  9. $copy_email = $_POST['CopyEmail'];
  10. $school = $_POST['School'];
  11. $room_number = $_POST['RoomNumber'];
  12. $equipment = $_POST['Equipment'];
  13. $idnumber = $_POST['IDNumber'];
  14. $manufacturer = $_POST['Manufacturer'];
  15. $model = $_POST['Model'];
  16. $serial_no = $_POST['SerialNo'];
  17. $problem = $_POST['Problem'];
  18. $contact = $_POST['Contact'];
  19. $date = date("F j, Y, g:i a");
  20.  
  21. //Validate first
  22. if(empty($contact)||empty($copy_email)) 
  23. {
  24.     echo "Name and email are mandatory!";
  25.     exit;
  26. }
  27.  
  28. if(IsInjected($copy_email))
  29. {
  30.     echo "Bad email value!";
  31.     exit;
  32. }
  33.  
  34. $email_subject = "Technology Work Order - $school";
  35. $email_body = "The following work order was entered on $date \r\n
  36.     SCHOOL: $school 
  37.     ROOM NUMBER: $room_number 
  38.     EQUIPMENT: $equipment 
  39.     ID NUMBER: $idnumber 
  40.     MANUFACTURER: $manufacturer 
  41.     MODEL: $model 
  42.     SERIAL NO: $serial_no
  43.     CONTACT: $contact 
  44.     PROBLEM: $problem \r\n";
  45.     
  46. $email_to = "psines@access.k12.wv.us,brrmarti@access.k12.wv.us,acorbitt@access.k12.wv.us";
  47. $headers = "From: $copy_email\r\n";
  48. $headers .= "CC: $copy_email\r\n";
  49.  
  50.  
  51. //Send the email!
  52. if (mail($email_to,$email_subject,$email_body,$headers)){
  53.  
  54.  
  55. //done. redirect to thank-you page.
  56. header('Location: thank-youworkpre.html');
  57. }
  58. else{
  59. header('Location: problem.html');
  60. }
  61.  
  62.  
  63. // Function to validate against any email injection attempts
  64. function IsInjected($str)
  65. {
  66.   $injections = array('(\n+)',
  67.               '(\r+)',
  68.               '(\t+)',
  69.               '(%0A+)',
  70.               '(%0D+)',
  71.               '(%08+)',
  72.               '(%09+)'
  73.               );
  74.   $inject = join('|', $injections);
  75.   $inject = "/$inject/i";
  76.   if(preg_match($inject,$str))
  77.     {
  78.     return true;
  79.   }
  80.   else
  81.     {
  82.     return false;
  83.   }
  84. }
  85.  
  86.  
  87. ?>